@extends('admin.base')
@section('title', '添加商品')
@section('content')

<div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
            @if($request['group_id'] > 0)
            <a href="/admin/group/index?page={{$request->page}}">返回拼团列表</a>
            @elseif($request['sku_id'] > 0)
            <a href="/admin/sku/index?id={{$request->id}}&page={{$request->page}}&keywords={{$request['keywords']}}&label={{$request['label']}}&type={{$request['type']}}&brand={{$request['brand']}}&state={{$request['state']}}&sell={{$request['state']}}&sell={{$request['sell']}}&month={{$request['month']}}&title={{$request->title}}">规格列表</a>
            @else
            <a href="/admin/shop/index?page={{$request->page}}&keywords={{$request['keywords']}}&label={{$request['label']}}&type={{$request['type']}}&brand={{$request['brand']}}&state={{$request['state']}}&sell={{$request['state']}}&sell={{$request['sell']}}&month={{$request['month']}}&title={{$request->title}}">商品列表</a>
            @endif    
                <a class="layui-btn-sm" href="" style="cursor:pointer;" ><cite>{{$gname}} - 拼团信息</cite></a>
                <!-- <a><cite>正文</cite></a> -->
            </span>
        </div>
    </fieldset>
    
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" method="post" action="{{url('/admin/group/insert')}}">
            @csrf
            <blockquote class="layui-elem-quote layui-quote-nm">

            <table class="layui-table" lay-even lay-size="">
            <colgroup>
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
            </colgroup>
            <thead>
                <tr>
                    <th class="tc">商品ID</th>
                    <th class="tc">货源ID</th>
                    <th class="tc">商品名</th>
                    <th class="tc">成本价</th>
                    <th class="tc">销售价</th>
                    <th class="tc">利润</th>
                </tr>
                <tbody>
                    <tr>
                        <td colspan="1" class="tc">{{$good['id']}}</td>
                        <td colspan="1" class="tc">{{$good['gid']}}</td>
                        <td colspan="1" class="tc">{{$good['name']}}</td>
                        <td colspan="1" class="tc">{{$good['cost_price']}}</td>
                        <td colspan="1" class="tc">{{$good['sell_price']}}</td>
                        <td colspan="1" class="tc">{{$good['sell_price'] - $good['cost_price']}}</td>

                    </tr>
                </tbody>
            </thead>
            </table>
            </blockquote>
            <blockquote class="layui-elem-quote">拼团参数设置</blockquote>


            <input type='hidden' name='gid' value="{{$request['id']}}">
            <input type='hidden' name='sku_id' value="{{$request['sku_id']}}">
        
            <div class="layui-form-item">
                <label class="layui-form-label">销售价</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="sell" value='{{$goods['sell']}}' required lay-verify="required" placeholder='请输入商品价' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">利润</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="charge" value='{{$goods['charge']}}' required lay-verify="required" placeholder='请输入商品利润，不填默认为初始利润' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">股票</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="number" name="shares" value='{{$goods['shares']}}' placeholder='请输入赠送股票' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">拼团数</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="nums" value='{{$goods['nums']}}' required lay-verify="required" placeholder='请输入拼团数' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="text" class="layui-input" id="test1" name='start' value="{{$goods['start']}}">
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline" style="width:30%;">
                <input type="text" class="layui-input" id="test2" name='end' value="{{$goods['end']}}">
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
        
          
        
            {{--<div class="layui-form-item layui-form-text" >--}}
                {{--<div class="layui-input-block" >--}}
            {{--<textarea name="content" id="content">--}}

            {{--</textarea>--}}
                {{--</div>--}}
            {{--</div>--}}
        @if($goods['is_exit'] == 2)
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>

        @else
            @if($type != 1)
            <div class="layui-form-item">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            @else
            @endif
        @endif
        </form>
    </div>
</div>
@endsection
@section('js')
<script type="text/javascript">

    layui.use(['layedit','form','laydate'],
        function() {
            var laydate = layui.laydate;
            var layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: '/admin/shop_editor',
                    type: 'post'
                }
            });
            var index = layedit.build('demo'); //建立编辑器
            var form = layui.form;
            var layedit = layui.layedit;
    
            //日期时间选择器
            laydate.render({ 
                elem: '#test1'
                ,format: 'yyyy-MM-dd HH:mm',
                type:"datetime"
            });
            laydate.render({ 
                elem: '#test2'
                ,format: 'yyyy-MM-dd HH:mm',
                type:"datetime"
            });

            //监听指定开关
            form.on('switch(switchTest)', function(data){
                var id = data.value;

                if(data.elem.checked){
                    var state = 1;//启用
                }else{
                    var state = 2;//禁用               
                }
                ajax('/admin/group/up_state',{id:id,state:state});
            });


            //监听提交
            form.on('submit(formDemo)', function(data){
                
                var aa = layedit.getContent(index);
                data.field.contents = aa;
                layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                    ajax("{{url('admin/group/insert')}}",data.field,function(data){
                        layer.close();
                        layer.closeAll();
                        layer.msg(data.msg);
                        if(data.code == 1){
                            location.href = "/admin/group/index";
                        }
                    });
                });
                return false;
            });
        });


</script>
@endsection
